//
//  UIView+Rect.swift
//  HTDevelop
//
//  Created by 李扬 on 2019/1/2.
//  Copyright © 2019 rrl360. All rights reserved.
//

import UIKit

public extension UIView {
    
    private var x : CGFloat {
        get { return frame.origin.x }
        set(newVal) {
            var tmpFrame : CGRect = frame
            tmpFrame.origin.x     = newVal
            frame                 = tmpFrame
        }
    }
    
    private var y : CGFloat {
        get { return frame.origin.y }
        set(newVal) {
            var tmpFrame : CGRect = frame
            tmpFrame.origin.y     = newVal
            frame                 = tmpFrame
        }
    }
    
    var height : CGFloat {
        get { return frame.size.height }
        set(newVal) {
            var tmpFrame : CGRect = frame
            tmpFrame.size.height  = newVal
            frame                 = tmpFrame
        }
    }
    
    var width : CGFloat {
        get { return frame.size.width }
        set(newVal) {
            var tmpFrame : CGRect = frame
            tmpFrame.size.width   = newVal
            frame                 = tmpFrame
        }
    }
    
    var left : CGFloat {
        get { return x }
        set(newVal) { x = newVal }
    }
    
    var right : CGFloat {
        get { return x + width }
        set(newVal) { x = newVal - width }
    }
    
    var top : CGFloat {
        get { return y }
        set(newVal) { y = newVal }
    }
    
    var bottom : CGFloat {
        get { return y + height }
        set(newVal) { y = newVal - height }
    }
    var centerX : CGFloat {
        get { return center.x }
        set(newVal) {
            center = CGPoint(x: newVal, y: center.y)
        }
    }
    var centerY : CGFloat {
        get { return center.y }
        set(newVal) {
            center = CGPoint(x: center.x, y: newVal)
        }
    }
    
    var b_center: CGPoint {
        get {
            return CGPoint.init(x: b_centerX, y: b_centerY)
        }
    }
    var b_centerX : CGFloat {
        get { return width / 2 }
    }
    var b_centerY : CGFloat {
        get { return height / 2 }
    }
    var f_origin: CGPoint  {
        get { return frame.origin }
        set(newVal) {
            var rect = self.frame
            rect.origin = newVal
            self.frame = rect
        }
    }
    var f_size: CGSize {
        get { return self.frame.size }
        set(newVal) {
            var rect = self.frame
            rect.size = newVal
            self.frame = rect
        }
    }
}

